package com.woniuxy.springboot.contorller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author 佘赛飞
 * @create 2021 -10 -08 11:00 AM
 */
@Controller
public class UserContorller {
    //@RequestMapping("/login.html")
//    @RequestMapping({"/","/index.html"})
//    public String toLogin(){
//        return "/login.html";
//    }

    @RequestMapping("/user/login")
    public String loing(HttpSession session, Model model, String username , String pwd){
        if("a".equals(username) && pwd.equals("aaa")){
            session.setAttribute("username", username);
            //    /templates/index.html
            //return "/index.html";
            //    /templates/login.html
            //return "redirect:/index.html";
            //post提交，F5刷新页面重复提交,使用重定向解决
            //return "/index.html";
            return "redirect:/main";
        }else {
          model.addAttribute("msg","用户名密码错误");
        }
        return "/login.html";
    }
}
